#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int captureForts(vector<int> &forts)
    {
        int ret = 0;
        int l = -1;
        for (int i = 0; i < forts.size(); i++)
        {
            if (forts[i] == 1 || forts[i] == -1)
            {
                if (l >= 0 && forts[i] != forts[l])
                {
                    ret = max(ret, i - l - 1);
                }
                l = i;
            }
        }
        return ret;
    };
};